// pages/mgzcomment/mgzcomment.js
//获取应用实例
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    magzine_id:'',
    periods:'',
    page_number:'',
    nv_id:'',
    page_type:''
  },
  // 页面第一次加载
  onLoad: function (options) {
    var that = this;
    that.setData({
      magzine_id :options.magzine_id,
      periods :options.periods,
      page_number : options.page_number,
      nv_id:options.nv_id
    })
  },
  bindTextAreaBlur:function(e){
    var that = this;
    var content = e.detail.value;
    if(content.length==0){
      wx.showModal({
        title: '提示',
        content: '请输入您的留言',
      })
    }else{
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app:'magzine',
            act:'getAddComment',
            magzine_id: that.options.magzine_id,
            periods: that.options.periods,
            page_number: that.options.page_number,
            content: content,
            t_session: session
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            wx.showModal({
              title: '提示',
              content: '留言成功',
              success: function (res) {
                if(that.data.nv_id==1){
                  that.setData({
                    page_type:'mgzvideo'
                  })
                } else if (that.data.nv_id==2){
                  that.setData({
                    page_type:'mgzproduct'
                  })
                }else{
                  that.setData({
                    page_type:'mgzmusic'
                  })
                }
                wx.navigateTo({
                  url: '/pages/' + that.data.page_type + "/" + that.data.page_type + "?id=" + that.options.magzine_id + "&&periods=" + that.options.periods + "&&page_number=" + that.options.page_number + "&&nv_id=" + that.data.nv_id
                })
              }
            })
          },
          fail: function (res) {
            wx.showModal({
              title: '提示',
              content: '留言失败'
            })
          },
        })
      })
    }
  },
})